package v3.chapter1.t19;

import java.util.Random;
 
public class Run {

	public static void main(String[] args) {
		for(int i=0;i<5;i++) {
			MyThread1 t1=new MyThread1();
			t1.setPriority(1);
			t1.start();
			
			MyThread2 t2=new MyThread2();
			t2.setPriority(10);
			t2.start();
		}
	}

}

class MyThread1 extends Thread {

	@Override
	public void run() {
		long beginTime = System.currentTimeMillis();
		long addResult = 0;
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < 5000; i++) {
				Random random = new Random();
				random.nextInt();
				addResult = addResult + i;
			}
		}

		long endTime = System.currentTimeMillis();
		System.out.println("★★★★★★ thread 1 use time=" + (endTime - beginTime));
	}

}

class MyThread2 extends Thread {

	@Override
	public void run() {
		long beginTime = System.currentTimeMillis();
		long addResult = 0;
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < 5000; i++) {
				Random random = new Random();
				random.nextInt();
				addResult = addResult + i;
			}
		}

		long endTime = System.currentTimeMillis();
		System.out.println("☆☆☆☆☆☆ thread 2 use time=" + (endTime - beginTime));
	}

}